<?php

class ApprovalController extends Zend_Controller_Action
{
    protected $db;
    
    public function init()
    {
        /* Initialize action controller here */
        /*if (!Zend_Auth::getInstance()->hasIdentity() || !isset(Zend_Auth::getInstance()->getIdentity()->username)) {
            $param = array(
            'action' => 'admin',
            'controller' => 'index',
            'msg' => 'Session Timeout silahkan login kembali !'
            );
            $this->_redirect($this->view->url($param, 'default', true));
        }
         * 
         */

        $session = new Zend_Session_Namespace('Zend_Auth_Admin');
        $this->sess = $session->data;

        $this->_helper->layout->setLayout('approval');

        if(!isset($this->sess)){
            $param = array(
            'action' => 'admin',
            'controller' => 'index',
            'msg' => 'Session Timeout silahkan login kembali !'
            );
            $this->_redirect($this->view->url($param, 'default', true));
        }

        $this->approval = new Application_Model_Approval();
        
        $this->request = $this->getRequest();
        $this->param = $this->request->getParams();

        $session->action = $this->param['action'];

    }

    public function indexAction()
    {

        //

    }
    


    public function withdrawAction()
    {

        ///
    }


    public function followupwithdrawAction()
    {

        if ($this->getRequest()->isPost()) {
            $this->_helper->layout->disableLayout();
            
            $formData  = $this->_request->getPost();
            
            $id   = $formData['trans_hid'];
            $flag = $formData['flag'];
            

            unset($formData['register']);

            //$auth = Zend_Auth::getInstance();
            //$identity = $auth->getIdentity();

            $dataT = $this->approval->prosesWithdraw($id, $flag);

            $msg = $dataT["msg"];
            $code = $dataT["code"];

            $this->view->code = $code;


            if($code == 0){
                $this->view->msg = $msg;
            }else{
                $this->view->msg = "ERROR ".$msg;
            }

        }else{

            
                $id = $this->param['id'];

                $data = $this->approval->detailWithdraw($id);

                $this->view->data = $data;
           
        }
    }

    public function topuppointAction()
    {

        ///
    }


    public function followuptopuppointAction()
    {

        if ($this->getRequest()->isPost()) {
            $this->_helper->layout->disableLayout();

            $formData  = $this->_request->getPost();

            $id   = $formData['trans_hid'];
            $flag = $formData['flag'];


            unset($formData['register']);

            //$auth = Zend_Auth::getInstance();
            //$identity = $auth->getIdentity();

            $dataT = $this->approval->prosesTopup($id, $flag);

            $msg = $dataT["msg"];
            $code = $dataT["code"];

            $this->view->code = $code;


            if($code == 0){
                $this->view->msg = $msg;
            }else{
                $this->view->msg = "ERROR ".$msg;
            }

        }else{


                $id = $this->param['id'];

                $data = $this->approval->detailTopupPoint($id);

                $this->view->data = $data;

        }
    }


   

}

